package com.ynny.chapter14.controller;


import com.ynny.chapter14.entity.R;
import com.ynny.chapter14.entity.User;

import com.ynny.chapter14.mapper.UserMapper;
import com.ynny.chapter14.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService UserService;
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/login")
    public R login(@RequestBody User users) {
        User user = UserService.login(users.getNumber(), users.getPassword());
        if (user != null) {
            return R.ok(user);
        }
        return R.fail(500, "用户名或密码错误");
    }
    @RequestMapping("/list")
    public R findAll() {
        return R.ok(userMapper.selectAll());
    }
}
